<?php
/**
 * 订餐菜品model
 */
class RestaurantGoodsModel extends BaseModel{
	protected $tableName='restaurant_goods';
	protected  $_link = array(
 		'RestaurantInfo' => array(
 			'mapping_type' => BELONGS_TO,
 			'class_name' => 'RestaurantInfo',
 			'foreign_key' => 'restaurant_id',
 			'mapping_fields' => 'restaurant_name',
 			'as_fields' => 'restaurant_name',
 		),
		'RestaurantGoodsCategory' => array(
 			'mapping_type' => BELONGS_TO,
 			'class_name' => 'RestaurantGoodsCategory',
 			'foreign_key' => 'category_id',
 			'mapping_fields' => 'category_name,window_id',
 			'as_fields' => 'category_name,window_id',
 		),
	);

	/**
	 *减库存,加销量
	 * @param array $condition
	 * @param int $num
	 * @return bool
	 */
	public function changeNum($condition,$num){
		//减库存
		$ret = D('RestaurantGoods')->where($condition)->setDec('goods_sum',$num);
		//加销量
		$ret1 = D('RestaurantGoods')->where($condition)->setInc('saled_num',$num);
		if($ret && $ret1){
			return true;
		}else{
			return false;
		}
	}
}